﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using System.Reflection;
using Medianamik.Core.Interfaces;

namespace Medianamik.Core.Querying
{
    public class NodeOrderBy : IMemberInfo
    {
        private MemberExpression _expression;
        public NodeOrderBy(MemberExpression pExpression, bool pDescending)
        {
            _expression = pExpression;
            Descending = pDescending;
        }

        private MemberInfo _memberInfo;
        public MemberInfo MemberInfo
        {
            get
            {
                if (_memberInfo == null)
                {
                    _memberInfo = _expression.Member;
                    if (!_memberInfo.DeclaringType.IsAssignableFrom(typeof(IQueryableNode)))
                    {
                        throw new ArgumentException("MemberExprssion must be from IQueryableNode");
                    }
                }
                return _memberInfo;
            }
        }

        public bool Descending { get; private set; }
    }

}
